package com.ucap.bbs.util;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.log4j.Logger;

public class InitConfig {
    public static final Map<String, String> INIT_CONFIG_MAP;
    static {
        Properties properties = readProperties("init.properties");
        INIT_CONFIG_MAP = new HashMap<String, String>();
        properties.entrySet();

        Set<Object> keys = properties.keySet();
        for (Iterator<Object> it = keys.iterator(); it.hasNext();) {
            String key = (String) it.next();
            String val = properties.getProperty(key);
            try {
                val = new String(val.getBytes("ISO-8859-1"),"UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            INIT_CONFIG_MAP.put(key, val);
        }
        Logger.getLogger(InitConfig.class).debug("InitConfig 初始化成功...");
    }

    public static Properties readProperties(String propertiesPath) {
        Properties properties = new Properties();
        try {
            properties.load(InitConfig.class.getClassLoader()
                    .getResourceAsStream(propertiesPath));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return properties;
    }
}
